package csu.web.credit_bank.service.impl;

import csu.web.credit_bank.mapper.UserLogsMapper;
import csu.web.credit_bank.pojo.UserLog;
import csu.web.credit_bank.service.UserLogsService;
import csu.web.credit_bank.utils.UUIDManager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserLogsServiceImpl extends ServiceImpl<UserLogsMapper, UserLog> implements UserLogsService {

    @Autowired
    private UUIDManager uuidManager;

    @Override
    public UserLog createLog(UserLog userLog) {
        String id = uuidManager.getUUID();
        if (id == null) {
            // 对于日志记录，获取ID失败不应阻塞主业务，可以考虑降级或记录错误
            System.err.println("ID池已空，无法创建日志记录");
            return null;
        }
        userLog.setId(id);
        this.save(userLog);
        return userLog;
    }

    @Override
    public UserLog getLogById(String id) {
        return this.getById(id);
    }

    @Override
    public UserLog updateLog(UserLog userLog) {
        this.updateById(userLog);
        return this.getById(userLog.getId());
    }

    @Override
    public boolean deleteLog(String id) {
        return this.removeById(id);
    }
}